package com.ruoyi.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.business.service.IWsdUserAccountService;
import com.ruoyi.common.core.domain.entity.WsdUserAccount;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户账户Controller
 *
 * @author ruoyi
 * @date 2024-06-19
 */
@RestController
@RequestMapping("/business/userAccount")
public class WsdUserAccountController extends BaseController
{
    @Autowired
    private IWsdUserAccountService wsdUserAccountService;

    /**
     * 查询用户账户列表
     */
    @PreAuthorize("@ss.hasPermi('business:userAccount:list')")
    @GetMapping("/list")
    public TableDataInfo list(WsdUserAccount wsdUserAccount)
    {
        startPage();
        List<WsdUserAccount> list = wsdUserAccountService.selectWsdUserAccountList(wsdUserAccount);
        return getDataTable(list);
    }

    /**
     * 导出用户账户列表
     */
    @PreAuthorize("@ss.hasPermi('business:userAccount:export')")
    @Log(title = "用户账户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WsdUserAccount wsdUserAccount)
    {
        List<WsdUserAccount> list = wsdUserAccountService.selectWsdUserAccountList(wsdUserAccount);
        ExcelUtil<WsdUserAccount> util = new ExcelUtil<WsdUserAccount>(WsdUserAccount.class);
        util.exportExcel(response, list, "用户账户数据");
    }

    /**
     * 获取用户账户详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:userAccount:query')")
    @GetMapping(value = "/{accountId}")
    public AjaxResult getInfo(@PathVariable("accountId") Long accountId)
    {
        return success(wsdUserAccountService.selectWsdUserAccountByAccountId(accountId));
    }

    /**
     * 新增用户账户
     */
    @PreAuthorize("@ss.hasPermi('business:userAccount:add')")
    @Log(title = "用户账户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WsdUserAccount wsdUserAccount)
    {
        return toAjax(wsdUserAccountService.insertWsdUserAccount(wsdUserAccount));
    }

    /**
     * 修改用户账户
     */
    @PreAuthorize("@ss.hasPermi('business:userAccount:edit')")
    @Log(title = "用户账户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WsdUserAccount wsdUserAccount)
    {
        return toAjax(wsdUserAccountService.updateWsdUserAccount(wsdUserAccount));
    }

    /**
     * 删除用户账户
     */
    @PreAuthorize("@ss.hasPermi('business:userAccount:remove')")
    @Log(title = "用户账户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{accountIds}")
    public AjaxResult remove(@PathVariable Long[] accountIds)
    {
        return toAjax(wsdUserAccountService.deleteWsdUserAccountByAccountIds(accountIds));
    }
}
